<?php namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller as BaseController;
use App\Models\Menu;
use Illuminate\Contracts\View\Factory as View;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Auth;

/**
 * 后台基础控制器
 *
 * @author Latrell Chan
 */
abstract class Controller extends BaseController
{
	//
	public function __construct(Request $request,View $view)
	{
        $this->middleware('auth.admin');
		//菜单管理
		$left_menu = Menu::where('status', 'Yes')->where('pid',0)->orderBy('sort', 'desc')->get();
		$view->share('left_menu', $left_menu);

//        $user = Auth::admin()->user();
//        $menus = Menu::whereIn('id',$user->menus)->get();
//        $menus_arr = [];
//        foreach ($menus as $key=>$item){
//            $menus_arr[] = $item->route;
//        }
//
//        if(!in_array($request->route()->getName(),$menus_arr)){
//            if ($request->ajax() || $request->wantsJson()) {
//                return response()->json([
//                    'status' => 403,
//                    'message' => '您没有权限',
//                    'data' => (object) null
//                ]);
//            }
//            return redirect()->to($this->getRedirectUrl())
//                ->withInput($request->input())
//                ->withErrors('您没有权限', $this->errorBag())
//                ->withMessageError('您没有权限');
//        }
	}
}
